<template>
  <div class="detail-nav-bar">
    <nav-bar>
      <!-- 左侧 -->
      <div slot="left" class="back" @click="backClick">
        <img src="~assets/images/common/back.svg" alt />
      </div>

      <!-- 中间 -->
      <div slot="center" class="title">
        <div
          class="title-item"
          v-for="(item, index) in titles"
          :key="'titile' + index"
          :class="{active: currentIndex == index}"
          @click="navClick(index)"
        >{{ item }}</div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
// 导入公共组件
import NavBar from "components/common/navbar/NavBar";

export default {
  name: "DetailNavBar",
  // 组件注册
  components: {
    NavBar,
  },
  // 组件数据
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      // 当前选中选项
      currentIndex: 0,
    };
  },
  // 组件方法
  methods: {
    // 返回上一级路由
    backClick() {
      this.$router.go(-1);
    },

    // 点击某个类型的详情
    navClick(index) {
      this.currentIndex = index;
      this.$emit("navClick", index);
    },
  },
};
</script>

<style lang="less" scoped>
.detail-nav-bar {
  .title {
    // 标题选项区域
    display: flex;
    .title-item {
      // 单个选项
      flex: 1;
      font-size: 14px;
    }
  }
  .active {
    // 选项激活样式
    color: var(--color-high-text);
  }
  .back {
    // 返回按钮
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>